#ifndef K_AERO_MANAGER_H_
#define K_AERO_MANAGER_H_

#include "qt_windows.h"
#include "QObject"
#include "QMargins"
#include "QLibrary"
#include "QString"

struct _MARGINS;
struct _DWM_BLURBEHIND;
struct _WINCOMPATTRDATA;

typedef HRESULT (WINAPI *PtrDwmIsCompositionEnabled)(BOOL* pfEnabled);
typedef HRESULT (WINAPI *PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const _MARGINS* pMarInset);
typedef HRESULT (WINAPI *PtrDwmEnableBlurBehindWindow)(HWND hWnd, __in const _DWM_BLURBEHIND* pBlurBehind);
typedef HRESULT (WINAPI *PtrDwmGetColorizationColor)(DWORD *pcrColorization, BOOL *pfOpaqueBlend);
typedef HRESULT (WINAPI *PtrDwmGetWindowAttribute)(HWND hwnd,DWORD dwAttribute,__out_bcount(cbAttribute) PVOID pvAttribute,DWORD cbAttribute);
typedef BOOL (WINAPI *PtrDwmDefWindowProc)(__in HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, __out LRESULT *plResult);
typedef BOOL (WINAPI *PtrDwmGetSharedSurface)(__in HWND hwnd, __out HANDLE *phSurface, __inout UINT64 *pAdapterLuid, __out DWORD *pFmtWindow, __out DWORD* pPresentFlags, __out UINT64* pWin32kUpdateId);
typedef BOOL (WINAPI *PtrSetWindowCompositionAttribute)(__in HWND hWnd, __inout _WINCOMPATTRDATA *pAttribData);

class KAeroManager
{
private:
	KAeroManager();
	
public:
	static bool enableBlurBehindWindow(QWidget * widget, bool enable = true);
	static bool extendFrameIntoClientArea(QWidget *widget,
									int left = -1, int right = -1,
									int top = -1, int bottom = -1);
	static bool extendFrameIntoClientArea(__in HWND hWnd,
									int left = -1, int right = -1,
									int top = -1, int bottom = -1);
	static bool extendFrameIntoClientArea(QWidget *w, QMargins m);
	static bool isCompositionEnabled();
	static bool isSupportBlurWindow();
	QColor colorizatinColor();

	static QRect getWindowSystemButtonRect(QWidget * widget);
	static HANDLE getSharedSurfaceHandle(__in HWND hWnd);

	static bool DwmDefWindowProc(__in HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, __out LRESULT *plResult);

private:
	static bool resolveLibs();

	static bool setBlurCompositionAttribute(QWidget *w, bool bOn);

private:
	static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled;
	static PtrDwmEnableBlurBehindWindow pDwmenableBlurBehindWindow;
	static PtrDwmExtendFrameIntoClientArea pDwmExtendFrameIntoClientArea;
	static PtrDwmGetColorizationColor pDwmGetColorizationColor;
	static PtrDwmGetWindowAttribute pDwmGetWindowAttribute;
	static PtrDwmDefWindowProc pDwmDefWindowProc;
	static PtrDwmGetSharedSurface pDwmGetSharedSurface;
	static PtrSetWindowCompositionAttribute pSetWindowCompositionAttribute;

private:
	static QScopedPointer<QLibrary> dwmLib;
};

#endif // K_AERO_MANAGER_H_
